/**
 * @author HuWen
 * @date 2025/8/11 9:15)
 */
public class ASCIITablePrinter {
    public static void main(String[] args) {
        // 打印表头
        System.out.println("ASCII码\t字符\t描述");
        System.out.println("------------------------");

        // 循环打印所有ASCII码（0-127）
        for (int i = 0; i <= 127; i++) {
            System.out.print(i + "\t");

            // 处理控制字符
            if (i < 32 || i == 127) {
                System.out.print("不可见\t");
                printControlCharacterDescription(i);
            } else {
                // 可打印字符直接输出
                System.out.print((char) i + "\t\t");
                System.out.println("可打印字符");
            }
        }
    }

    // 打印控制字符的描述
    private static void printControlCharacterDescription(int code) {
        switch (code) {
            case 0:  System.out.println("空字符 (NUL)"); break;
            case 1:  System.out.println("标题开始 (SOH)"); break;
            case 2:  System.out.println("文本开始 (STX)"); break;
            case 3:  System.out.println("文本结束 (ETX)"); break;
            case 4:  System.out.println("传输结束 (EOT)"); break;
            case 5:  System.out.println("请求 (ENQ)"); break;
            case 6:  System.out.println("确认 (ACK)"); break;
            case 7:  System.out.println("响铃 (BEL)"); break;
            case 8:  System.out.println("退格 (BS)"); break;
            case 9:  System.out.println("水平制表符 (HT)"); break;
            case 10: System.out.println("换行 (LF)"); break;
            case 11: System.out.println("垂直制表符 (VT)"); break;
            case 12: System.out.println("换页 (FF)"); break;
            case 13: System.out.println("回车 (CR)"); break;
            case 14: System.out.println("移位输出 (SO)"); break;
            case 15: System.out.println("移位输入 (SI)"); break;
            case 16: System.out.println("数据链路转义 (DLE)"); break;
            case 17: System.out.println("设备控制1 (DC1)"); break;
            case 18: System.out.println("设备控制2 (DC2)"); break;
            case 19: System.out.println("设备控制3 (DC3)"); break;
            case 20: System.out.println("设备控制4 (DC4)"); break;
            case 21: System.out.println("否定 (NAK)"); break;
            case 22: System.out.println("同步空闲 (SYN)"); break;
            case 23: System.out.println("传输块结束 (ETB)"); break;
            case 24: System.out.println("取消 (CAN)"); break;
            case 25: System.out.println("介质结束 (EM)"); break;
            case 26: System.out.println("替换 (SUB)"); break;
            case 27: System.out.println("转义 (ESC)"); break;
            case 28: System.out.println("文件分隔符 (FS)"); break;
            case 29: System.out.println("组分隔符 (GS)"); break;
            case 30: System.out.println("记录分隔符 (RS)"); break;
            case 31: System.out.println("单元分隔符 (US)"); break;
            case 127:System.out.println("删除 (DEL)"); break;
            default: System.out.println("控制字符");
        }
    }
}


